/**
 * Copyright (c) 2015-2019, Golly Hu 胡高 (3722711@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.hg.jfsa.manage.controller.module.contactRequest;

import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import cn.hg.base.jfinal.controller.BaseController;
import cn.hg.base.kit.StrExtKit;
import cn.hg.jfsa.manage.web.LayuiPage;
import cn.hg.jfsa.model.ContactRequest;
import cn.hg.jfsa.web.theme.ThemeManager;

/**
 * @author Golly
 */
public class ContactRequestController extends BaseController {

	public void ajaxSearch () {
		// 建立查询键值对
		Kv para = Kv.by("sortField", StrExtKit.humpToUnderline(this.getPara("sortField")))
			.set("name", this.getPara("name"))
			.set("sortType", this.getPara("sortType"))
			.set("theme", ThemeManager.me().getCurrentTheme().getId());
		// 通过SQL模板引擎构建SQL及参数
		SqlPara sqlPara = Db.getSqlPara("module.findContactRequest", para);
		// 执行查询
		Page<ContactRequest> page =
			ContactRequest.DAO.paginate(this.getParaToInt("page"), this.getParaToInt("limit"), sqlPara);
		// 返回Ajax调用的Json结果
		this.renderJson(new LayuiPage(page));
	}

	@Override
	public void index () {
		// TODO Auto-generated method stub
	}

	public void view () {
		this.setAttr("contactRequest", ContactRequest.DAO.findById(this.getParaToInt("id")));
	}

}
